home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / combatsc.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  17KB  |  674 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/konamiic.h"
  11. #include "vidhrdw/generic.h"
  12.  
  13. static struct tilemap *tilemap[2];
  14. static struct tilemap *textlayer;
  15. static unsigned char *private_spriteram[2];
  16. static int priority;
  17.  
  18. unsigned char *combasc_io_ram;
  19. static int combasc_vreg;
  20. unsigned char* banked_area;
  21.  
  22. static int combasc_bank_select; /* 0x00..0x1f */
  23. static int combasc_video_circuit; /* 0 or 1 */
  24. static unsigned char *combasc_page[2];
  25. static unsigned char combasc_scrollram0[0x40];
  26. static unsigned char combasc_scrollram1[0x40];
  27. static unsigned char *combasc_scrollram;
  28.  
  29.  
  30. void combasc_convert_color_prom(unsigned char *palette, unsigned short *colortable, const unsigned char *color_prom )
  31. {
  32.     int i,pal,clut = 0;
  33.     for( pal=0; pal<8; pal++ )
  34.     {
  35.         switch( pal )
  36.         {
  37.             case 0: /* other sprites */
  38.             case 2: /* other sprites(alt) */
  39.             clut = 1;    /* 0 is wrong for Firing Range III targets */
  40.             break;
  41.  
  42.             case 4: /* player sprites */
  43.             case 6: /* player sprites(alt) */
  44.             clut = 2;
  45.             break;
  46.  
  47.             case 1: /* background */
  48.             case 3: /* background(alt) */
  49.             clut = 1;
  50.             break;
  51.  
  52.             case 5: /* foreground tiles */
  53.             case 7: /* foreground tiles(alt) */
  54.             clut = 3;
  55.             break;
  56.         }
  57.  
  58.         for( i=0; i<256; i++ )
  59.         {
  60.             if ((pal & 1) == 0)    /* sprites */
  61.             {
  62.                 if (color_prom[256 * clut + i] == 0)
  63.                     *(colortable++) = 0;
  64.                 else
  65.                     *(colortable++) = 16 * pal + color_prom[256 * clut + i];
  66.             }
  67.             else    /* chars */
  68.                 *(colortable++) = 16 * pal + color_prom[256 * clut + i];
  69.         }
  70.     }
  71. }
  72.  
  73. void combascb_convert_color_prom(unsigned char *palette, unsigned short *colortable, const unsigned char *color_prom )
  74. {
  75.     int i,pal;
  76.     for( pal=0; pal<8; pal++ )
  77.     {
  78.         for( i=0; i<256; i++ )
  79.         {
  80.             if ((pal & 1) == 0)    /* sprites */
  81.                 *(colortable++) = 16 * pal + (color_prom[i] ^ 0x0f);
  82.             else    /* chars */
  83.                 *(colortable++) = 16 * pal + (i & 0x0f);    /* no lookup? */
  84.         }
  85.     }
  86. }
  87.  
  88. /***************************************************************************
  89.  
  90.     Callbacks for the TileMap code
  91.  
  92. ***************************************************************************/
  93.  
  94. static void get_tile_info0(int tile_index)
  95. {
  96.     unsigned char attributes = combasc_page[0][tile_index];
  97.     int bank = 4*((combasc_vreg & 0x0f) - 1);
  98.     int number,color;
  99.  
  100.     if (bank < 0) bank = 0;
  101.     if ((attributes & 0xb0) == 0) bank = 0;    /* text bank */
  102.  
  103.     if (attributes & 0x80) bank += 1;
  104.     if (attributes & 0x10) bank += 2;
  105.     if (attributes & 0x20) bank += 4;
  106.  
  107.     color = ((K007121_ctrlram[0][6]&0x10)*2+16) + (attributes & 0x0f);
  108.  
  109.     number = combasc_page[0][tile_index + 0x400] + 256*bank;
  110.  
  111.     SET_TILE_INFO(0,number,color)
  112.     tile_info.priority = (attributes & 0x40) >> 6;
  113. }
  114.  
  115. static void get_tile_info1(int tile_index)
  116. {
  117.     unsigned char attributes = combasc_page[1][tile_index];
  118.     int bank = 4*((combasc_vreg >> 4) - 1);
  119.     int number, color;
  120.  
  121.     if (bank < 0) bank = 0;
  122.     if ((attributes & 0xb0) == 0) bank = 0;    /* text bank */
  123.  
  124.     if (attributes & 0x80) bank += 1;
  125.     if (attributes & 0x10) bank += 2;
  126.     if (attributes & 0x20) bank += 4;
  127.  
  128.     color = ((K007121_ctrlram[1][6]&0x10)*2+16+4*16) + (attributes & 0x0f);
  129.  
  130.     number = combasc_page[1][tile_index + 0x400] + 256*bank;
  131.  
  132.     SET_TILE_INFO(1,number,color)
  133.     tile_info.priority = (attributes & 0x40) >> 6;
  134. }
  135.  
  136. static void get_text_info(int tile_index)
  137. {
  138.     unsigned char attributes = combasc_page[0][tile_index + 0x800];
  139.     int number = combasc_page[0][tile_index + 0xc00];
  140.     int color = 16 + (attributes & 0x0f);
  141.  
  142.     SET_TILE_INFO(0,number,color)
  143.  
  144.     /* the following hack is needed because the TileMap system doesn't support TRANSPARENCY_COLOR */
  145.     tile_info.flags = 0;
  146.     if ((attributes & 0x0f) == 0x01 || (attributes & 0x0f) == 0x0e)
  147.         tile_info.flags = TILE_IGNORE_TRANSPARENCY;
  148. }
  149.  
  150.  
  151. static void get_tile_info0_bootleg(int tile_index)
  152. {
  153.     unsigned char attributes = combasc_page[0][tile_index];
  154.     int bank = 4*((combasc_vreg & 0x0f) - 1);
  155.     int number, pal, color;
  156.  
  157.     if (bank < 0) bank = 0;
  158.     if ((attributes & 0xb0) == 0) bank = 0;    /* text bank */
  159.  
  160.     if (attributes & 0x80) bank += 1;
  161.     if (attributes & 0x10) bank += 2;
  162.     if (attributes & 0x20) bank += 4;
  163.  
  164.     pal = (bank == 0 || bank >= 0x1c || (attributes & 0x40)) ? 1 : 3;
  165.     color = pal*16;// + (attributes & 0x0f);
  166.     number = combasc_page[0][tile_index + 0x400] + 256*bank;
  167.  
  168.     SET_TILE_INFO(0,number,color)
  169. }
  170.  
  171. static void get_tile_info1_bootleg(int tile_index)
  172. {
  173.     unsigned char attributes = combasc_page[1][tile_index];
  174.     int bank = 4*((combasc_vreg >> 4) - 1);
  175.     int number, pal, color;
  176.  
  177.     if (bank < 0) bank = 0;
  178.     if ((attributes & 0xb0) == 0) bank = 0;    /* text bank */
  179.  
  180.     if (attributes & 0x80) bank += 1;
  181.     if (attributes & 0x10) bank += 2;
  182.     if (attributes & 0x20) bank += 4;
  183.  
  184.     pal = (bank == 0 || bank >= 0x1c || (attributes & 0x40)) ? 5 : 7;
  185.     color = pal*16;// + (attributes & 0x0f);
  186.     number = combasc_page[1][tile_index + 0x400] + 256*bank;
  187.  
  188.     SET_TILE_INFO(1,number,color)
  189. }
  190.  
  191. static void get_text_info_bootleg(int tile_index)
  192. {
  193. //    unsigned char attributes = combasc_page[0][tile_index + 0x800];
  194.     int number = combasc_page[0][tile_index + 0xc00];
  195.     int color = 16;// + (attributes & 0x0f);
  196.  
  197.     SET_TILE_INFO(1, number, color)
  198. }
  199.  
  200. /***************************************************************************
  201.  
  202.     Start the video hardware emulation.
  203.  
  204. ***************************************************************************/
  205.  
  206. int combasc_vh_start(void)
  207. {
  208.     combasc_vreg = -1;
  209.  
  210.     tilemap[0] = tilemap_create(get_tile_info0,tilemap_scan_rows,TILEMAP_TRANSPARENT,8,8,32,32);
  211.     tilemap[1] = tilemap_create(get_tile_info1,tilemap_scan_rows,TILEMAP_TRANSPARENT,8,8,32,32);
  212.     textlayer =  tilemap_create(get_text_info, tilemap_scan_rows,TILEMAP_TRANSPARENT,8,8,32,32);
  213.  
  214.     private_spriteram[0] = malloc(0x800);
  215.     private_spriteram[1] = malloc(0x800);
  216.     memset(private_spriteram[0],0,0x800);
  217.     memset(private_spriteram[1],0,0x800);
  218.  
  219.     if (tilemap[0] && tilemap[1] && textlayer)
  220.     {
  221.         tilemap[0]->transparent_pen = 0;
  222.         tilemap[1]->transparent_pen = 0;
  223.         textlayer->transparent_pen = 0;
  224.  
  225.         tilemap_set_scroll_rows(textlayer,32);
  226.  
  227.         return 0;
  228.     }
  229.  
  230.     return 1;
  231. }
  232.  
  233. int combascb_vh_start(void)
  234. {
  235.     combasc_vreg = -1;
  236.  
  237.     tilemap[0] = tilemap_create(get_tile_info0_bootleg,tilemap_scan_rows,TILEMAP_TRANSPARENT,8,8,32,32);
  238.     tilemap[1] = tilemap_create(get_tile_info1_bootleg,tilemap_scan_rows,TILEMAP_TRANSPARENT,8,8,32,32);
  239.     textlayer =  tilemap_create(get_text_info_bootleg, tilemap_scan_rows,TILEMAP_TRANSPARENT,8,8,32,32);
  240.  
  241.     private_spriteram[0] = malloc(0x800);
  242.     private_spriteram[1] = malloc(0x800);
  243.     memset(private_spriteram[0],0,0x800);
  244.     memset(private_spriteram[1],0,0x800);
  245.  
  246.     if (tilemap[0] && tilemap[1] && textlayer)
  247.     {
  248.         tilemap[0]->transparent_pen = 0;
  249.         tilemap[1]->transparent_pen = 0;
  250.         textlayer->transparent_pen = 0;
  251.  
  252.         tilemap_set_scroll_rows(tilemap[0],32);
  253.         tilemap_set_scroll_rows(tilemap[1],32);
  254.  
  255.         return 0;
  256.     }
  257.  
  258.     return 1;
  259. }
  260.  
  261. void combasc_vh_stop(void)
  262. {
  263.     free(private_spriteram[0]);
  264.     free(private_spriteram[1]);
  265. }
  266.  
  267.  
  268. /***************************************************************************
  269.  
  270.     Memory handlers
  271.  
  272. ***************************************************************************/
  273.  
  274. READ_HANDLER( combasc_video_r )
  275. {
  276.     return videoram[offset];
  277. }
  278.  
  279. WRITE_HANDLER( combasc_video_w )
  280. {
  281.     if( videoram[offset]!=data )
  282.     {
  283.         videoram[offset] = data;
  284.         if( offset<0x800 )
  285.         {
  286.             if (combasc_video_circuit)
  287.                 tilemap_mark_tile_dirty(tilemap[1],offset & 0x3ff);
  288.             else
  289.                 tilemap_mark_tile_dirty(tilemap[0],offset & 0x3ff);
  290.         }
  291.         else if( offset<0x1000 && combasc_video_circuit==0 )
  292.         {
  293.             tilemap_mark_tile_dirty( textlayer,offset & 0x3ff);
  294.         }
  295.     }
  296. }
  297.  
  298.  
  299. WRITE_HANDLER( combasc_vreg_w )
  300. {
  301.     if (data != combasc_vreg)
  302.     {
  303.         tilemap_mark_all_tiles_dirty( textlayer );
  304.         if ((data & 0x0f) != (combasc_vreg & 0x0f))
  305.             tilemap_mark_all_tiles_dirty( tilemap[0] );
  306.         if ((data >> 4) != (combasc_vreg >> 4))
  307.             tilemap_mark_all_tiles_dirty( tilemap[1] );
  308.         combasc_vreg = data;
  309.     }
  310. }
  311.  
  312. WRITE_HANDLER( combascb_sh_irqtrigger_w )
  313. {
  314.     soundlatch_w(offset,data);
  315.     cpu_cause_interrupt(1,0xff);
  316. }
  317.  
  318. READ_HANDLER( combasc_io_r )
  319. {
  320.     if ((offset <= 0x403) && (offset >= 0x400))
  321.     {
  322.         switch (offset)
  323.         {
  324.             case 0x400:    return input_port_0_r(0); break;
  325.             case 0x401:    return input_port_1_r(0); break;
  326.             case 0x402:    return input_port_2_r(0); break;
  327.             case 0x403:    return input_port_3_r(0); break;
  328.         }
  329.     }
  330.     return banked_area[offset];
  331. }
  332.  
  333. WRITE_HANDLER( combasc_io_w )
  334. {
  335.     switch (offset)
  336.     {
  337.         case 0x400: priority = data & 0x20; break;
  338.         case 0x800: combascb_sh_irqtrigger_w(0, data); break;
  339.         case 0xc00:    combasc_vreg_w(0, data); break;
  340.         default:
  341.             combasc_io_ram[offset] = data;
  342.     }
  343. }
  344.  
  345. WRITE_HANDLER( combasc_bankselect_w )
  346. {
  347.     unsigned char *page = memory_region(REGION_CPU1) + 0x10000;
  348.  
  349.     if (data & 0x40)
  350.     {
  351.         combasc_video_circuit = 1;
  352.         videoram = combasc_page[1];
  353.         combasc_scrollram = combasc_scrollram1;
  354.     }
  355.     else
  356.     {
  357.         combasc_video_circuit = 0;
  358.         videoram = combasc_page[0];
  359.         combasc_scrollram = combasc_scrollram0;
  360.     }
  361.  
  362.     priority = data & 0x20;
  363.  
  364.     if (data & 0x10)
  365.     {
  366.         cpu_setbank(1,page + 0x4000 * ((data & 0x0e) >> 1));
  367.     }
  368.     else
  369.     {
  370.         cpu_setbank(1,page + 0x20000 + 0x4000 * (data & 1));
  371.     }
  372. }
  373.  
  374. WRITE_HANDLER( combascb_bankselect_w )
  375. {
  376.     if (data & 0x40)
  377.     {
  378.         combasc_video_circuit = 1;
  379.         videoram = combasc_page[1];
  380.     }
  381.     else
  382.     {
  383.         combasc_video_circuit = 0;
  384.         videoram = combasc_page[0];
  385.     }
  386.  
  387.     data = data & 0x1f;
  388.     if( data != combasc_bank_select )
  389.     {
  390.         unsigned char *page = memory_region(REGION_CPU1) + 0x10000;
  391.         combasc_bank_select = data;
  392.  
  393.         if (data & 0x10)
  394.         {
  395.             cpu_setbank(1,page + 0x4000 * ((data & 0x0e) >> 1));
  396.         }
  397.         else
  398.         {
  399.             cpu_setbank(1,page + 0x20000 + 0x4000 * (data & 1));
  400.         }
  401.  
  402.         if (data == 0x1f)
  403.         {
  404. cpu_setbank(1,page + 0x20000 + 0x4000 * (data & 1));
  405.             cpu_setbankhandler_r (1, combasc_io_r);/* IO RAM & Video Registers */
  406.             cpu_setbankhandler_w (1, combasc_io_w);
  407.         }
  408.         else
  409.         {
  410.             cpu_setbankhandler_r (1, MRA_BANK1);    /* banked ROM */
  411.             cpu_setbankhandler_w (1, MWA_ROM);
  412.         }
  413.     }
  414. }
  415.  
  416. void combasc_init_machine( void )
  417. {
  418.     unsigned char *MEM = memory_region(REGION_CPU1) + 0x38000;
  419.  
  420.  
  421.     combasc_io_ram  = MEM + 0x0000;
  422.     combasc_page[0] = MEM + 0x4000;
  423.     combasc_page[1] = MEM + 0x6000;
  424.  
  425.     memset( combasc_io_ram,  0x00, 0x4000 );
  426.     memset( combasc_page[0], 0x00, 0x2000 );
  427.     memset( combasc_page[1], 0x00, 0x2000 );
  428.  
  429.     combasc_bank_select = -1;
  430.     combasc_bankselect_w( 0,0 );
  431. }
  432.  
  433. WRITE_HANDLER( combasc_pf_control_w )
  434. {
  435.     K007121_ctrl_w(combasc_video_circuit,offset,data);
  436.  
  437.     if (offset == 7)
  438.         tilemap_set_flip(tilemap[combasc_video_circuit],(data & 0x08) ? (TILEMAP_FLIPY | TILEMAP_FLIPX) : 0);
  439.  
  440.     if (offset == 3)
  441.     {
  442.         if (data & 0x08)
  443.             memcpy(private_spriteram[combasc_video_circuit],combasc_page[combasc_video_circuit]+0x1000,0x800);
  444.         else
  445.             memcpy(private_spriteram[combasc_video_circuit],combasc_page[combasc_video_circuit]+0x1800,0x800);
  446.     }
  447. }
  448.  
  449. READ_HANDLER( combasc_scrollram_r )
  450. {
  451.     return combasc_scrollram[offset];
  452. }
  453.  
  454. WRITE_HANDLER( combasc_scrollram_w )
  455. {
  456.     combasc_scrollram[offset] = data;
  457. }
  458.  
  459.  
  460.  
  461. /***************************************************************************
  462.  
  463.     Display Refresh
  464.  
  465. ***************************************************************************/
  466.  
  467. static void draw_sprites(struct osd_bitmap *bitmap, const unsigned char *source,int circuit,UINT32 pri_mask)
  468. {
  469.     int base_color = (circuit*4)*16+(K007121_ctrlram[circuit][6]&0x10)*2;
  470.  
  471.     K007121_sprites_draw(circuit,bitmap,source,base_color,0,0,pri_mask);
  472. }
  473.  
  474.  
  475. void combasc_vh_screenrefresh( struct osd_bitmap *bitmap, int fullrefresh )
  476. {
  477.     int i;
  478.  
  479.  
  480.     if (K007121_ctrlram[0][0x01] & 0x02)
  481.     {
  482.         tilemap_set_scroll_rows(tilemap[0],32);
  483.         for (i = 0;i < 32;i++)
  484.         {
  485.             tilemap_set_scrollx(tilemap[0],i,combasc_scrollram0[i]);
  486.         }
  487.     }
  488.     else
  489.     {
  490.         tilemap_set_scroll_rows(tilemap[0],1);
  491.         tilemap_set_scrollx(tilemap[0],0,K007121_ctrlram[0][0x00] | ((K007121_ctrlram[0][0x01] & 0x01) << 8));
  492.     }
  493.  
  494.     if (K007121_ctrlram[1][0x01] & 0x02)
  495.     {
  496.         tilemap_set_scroll_rows(tilemap[1],32);
  497.         for (i = 0;i < 32;i++)
  498.         {
  499.             tilemap_set_scrollx(tilemap[1],i,combasc_scrollram1[i]);
  500.         }
  501.     }
  502.     else
  503.     {
  504.         tilemap_set_scroll_rows(tilemap[1],1);
  505.         tilemap_set_scrollx( tilemap[1],0,K007121_ctrlram[1][0x00] | ((K007121_ctrlram[1][0x01] & 0x01) << 8));
  506.     }
  507.  
  508.     tilemap_set_scrolly(tilemap[0],0,K007121_ctrlram[0][0x02]);
  509.     tilemap_set_scrolly(tilemap[1],0,K007121_ctrlram[1][0x02]);
  510.  
  511.     tilemap_update(ALL_TILEMAPS);
  512.     if (palette_recalc())
  513.         tilemap_mark_all_pixels_dirty(ALL_TILEMAPS);
  514.     tilemap_render(ALL_TILEMAPS);
  515.  
  516.     fillbitmap(priority_bitmap,0,NULL);
  517.  
  518.     if (priority == 0)
  519.     {
  520.         tilemap_draw(bitmap,tilemap[1],TILEMAP_IGNORE_TRANSPARENCY|0|(4<<16));
  521.         tilemap_draw(bitmap,tilemap[1],TILEMAP_IGNORE_TRANSPARENCY|1|(8<<16));
  522.         tilemap_draw(bitmap,tilemap[0],0|(1<<16));
  523.         tilemap_draw(bitmap,tilemap[0],1|(2<<16));
  524.  
  525.         /* we use the priority buffer so sprites are drawn front to back */
  526.         draw_sprites(bitmap,private_spriteram[1],1,0x0f00);
  527.         draw_sprites(bitmap,private_spriteram[0],0,0x4444);
  528.     }
  529.     else
  530.     {
  531.         tilemap_draw(bitmap,tilemap[0],TILEMAP_IGNORE_TRANSPARENCY|0|(1<<16));
  532.         tilemap_draw(bitmap,tilemap[0],TILEMAP_IGNORE_TRANSPARENCY|1|(2<<16));
  533.         tilemap_draw(bitmap,tilemap[1],1|(4<<16));
  534.         tilemap_draw(bitmap,tilemap[1],0|(8<<16));
  535.  
  536.         /* we use the priority buffer so sprites are drawn front to back */
  537.         draw_sprites(bitmap,private_spriteram[1],1,0x0f00);
  538.         draw_sprites(bitmap,private_spriteram[0],0,0x4444);
  539.     }
  540.  
  541.     if (K007121_ctrlram[0][0x01] & 0x08)
  542.     {
  543.         for (i = 0;i < 32;i++)
  544.         {
  545.             tilemap_set_scrollx(textlayer,i,combasc_scrollram0[0x20+i] ? 0 : TILE_LINE_DISABLED);
  546.             tilemap_draw(bitmap,textlayer,0);
  547.         }
  548.     }
  549.  
  550.     /* chop the extreme columns if necessary */
  551.     if (K007121_ctrlram[0][0x03] & 0x40)
  552.     {
  553.         struct rectangle clip;
  554.  
  555.         clip = Machine->drv->visible_area;
  556.         clip.max_x = clip.min_x + 7;
  557.         fillbitmap(bitmap,Machine->pens[0],&clip);
  558.  
  559.         clip = Machine->drv->visible_area;
  560.         clip.min_x = clip.max_x - 7;
  561.         fillbitmap(bitmap,Machine->pens[0],&clip);
  562.     }
  563. }
  564.  
  565.  
  566.  
  567.  
  568.  
  569.  
  570.  
  571.  
  572. /***************************************************************************
  573.  
  574.     bootleg Combat School sprites. Each sprite has 5 bytes:
  575.  
  576. byte #0:    sprite number
  577. byte #1:    y position
  578. byte #2:    x position
  579. byte #3:
  580.     bit 0:        x position (bit 0)
  581.     bits 1..3:    ???
  582.     bit 4:        flip x
  583.     bit 5:        unused?
  584.     bit 6:        sprite bank # (bit 2)
  585.     bit 7:        ???
  586. byte #4:
  587.     bits 0,1:    sprite bank # (bits 0 & 1)
  588.     bits 2,3:    unused?
  589.     bits 4..7:    sprite color
  590.  
  591. ***************************************************************************/
  592.  
  593. static void bootleg_draw_sprites( struct osd_bitmap *bitmap, const unsigned char *source, int circuit )
  594. {
  595.     const struct GfxElement *gfx = Machine->gfx[circuit+2];
  596.     const struct rectangle *clip = &Machine->drv->visible_area;
  597.  
  598.     unsigned char *RAM = memory_region(REGION_CPU1);
  599.     int limit = ( circuit) ? (RAM[0xc2]*256 + RAM[0xc3]) : (RAM[0xc0]*256 + RAM[0xc1]);
  600.     const unsigned char *finish;
  601.  
  602.     source+=0x1000;
  603.     finish = source;
  604.     source+=0x400;
  605.     limit = (0x3400-limit)/8;
  606.     if( limit>=0 ) finish = source-limit*8;
  607.     source-=8;
  608.  
  609.     while( source>finish )
  610.     {
  611.         unsigned char attributes = source[3]; /* PBxF ?xxX */
  612.         {
  613.             int number = source[0];
  614.             int x = source[2] - 71 + (attributes & 0x01)*256;
  615.             int y = 242 - source[1];
  616.             unsigned char color = source[4]; /* CCCC xxBB */
  617.  
  618.             int bank = (color & 0x03) | ((attributes & 0x40) >> 4);
  619.  
  620.             number = ((number & 0x02) << 1) | ((number & 0x04) >> 1) | (number & (~6));
  621.             number += 256*bank;
  622.  
  623.             color = (circuit*4)*16 + (color >> 4);
  624.  
  625.             /*    hacks to select alternate palettes */
  626. //            if(combasc_vreg == 0x40 && (attributes & 0x40)) color += 1*16;
  627. //            if(combasc_vreg == 0x23 && (attributes & 0x02)) color += 1*16;
  628. //            if(combasc_vreg == 0x66 ) color += 2*16;
  629.  
  630.             drawgfx( bitmap, gfx,
  631.                 number, color,
  632.                 attributes & 0x10,0, /* flip */
  633.                 x,y,
  634.                 clip, TRANSPARENCY_PEN, 15 );
  635.         }
  636.         source -= 8;
  637.     }
  638. }
  639.  
  640. void combascb_vh_screenrefresh( struct osd_bitmap *bitmap, int fullrefresh )
  641. {
  642.     int i;
  643.  
  644.     for( i=0; i<32; i++ )
  645.     {
  646.         tilemap_set_scrollx( tilemap[0],i, combasc_io_ram[0x040+i]+5 );
  647.         tilemap_set_scrollx( tilemap[1],i, combasc_io_ram[0x060+i]+3 );
  648.     }
  649.     tilemap_set_scrolly( tilemap[0],0, combasc_io_ram[0x000] );
  650.     tilemap_set_scrolly( tilemap[1],0, combasc_io_ram[0x020] );
  651.  
  652.     tilemap_update( ALL_TILEMAPS );
  653.     if (palette_recalc())
  654.         tilemap_mark_all_pixels_dirty(ALL_TILEMAPS);
  655.     tilemap_render( ALL_TILEMAPS );
  656.  
  657.     if (priority == 0)
  658.     {
  659.         tilemap_draw( bitmap,tilemap[1],TILEMAP_IGNORE_TRANSPARENCY );
  660.         bootleg_draw_sprites( bitmap, combasc_page[0], 0 );
  661.         tilemap_draw( bitmap,tilemap[0],0 );
  662.         bootleg_draw_sprites( bitmap, combasc_page[1], 1 );
  663.     }
  664.     else
  665.     {
  666.         tilemap_draw( bitmap,tilemap[0],TILEMAP_IGNORE_TRANSPARENCY );
  667.         bootleg_draw_sprites( bitmap, combasc_page[0], 0 );
  668.         tilemap_draw( bitmap,tilemap[1],0 );
  669.         bootleg_draw_sprites( bitmap, combasc_page[1], 1 );
  670.     }
  671.  
  672.     tilemap_draw( bitmap,textlayer,0 );
  673. }
  674.